package com.rdc.dictionary.mvpBase;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.rdc.dictionary.mvpActivity.ActivityDelegate;
import com.rdc.dictionary.mvpActivity.ActivityDelegateImp;
import com.rdc.dictionary.mvpActivity.ActivityMvpDelegateCallback;
import com.rdc.dictionary.mvpPresenters.MvpPresenter;

/**
 * @author Soul Mate
 * @file 文件名
 * @brief MVP Activity的基类
 */

public abstract class BaseMvpActivity<P extends MvpPresenter, V extends MvpView> extends
		AppCompatActivity implements ActivityMvpDelegateCallback<P, V>, MvpView {
	private ActivityDelegate mActivityDelegate;
	private P mPresenter;


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mActivityDelegate = new ActivityDelegateImp<>(this);
		mActivityDelegate.onCreate();

		//加载布局
		setContentView(getLayoutResId());


		init();


	}

	@Override
	protected void onResume() {
		super.onResume();
		mActivityDelegate.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
		mActivityDelegate.onPause();
	}

	@Override
	protected void onStop() {
		super.onStop();
		mActivityDelegate.onStop();
	}


	@Override
	public void setPresenter() {

	}

	public abstract void onDestroy(Bundle savedInstanceState);

	//暴露一个创建的方法用于创建presenter
	protected abstract P CreatePresenter();

	@Override
	//这个方法由MvpInternalDelegate 调用 BaseDelegateCallback 来创建Presenter
	public P createPresenter()

	{
		mPresenter = CreatePresenter();
		return mPresenter;
	}

	@Override
	public P getPresenter() {
		return mPresenter;
	}

	@Override
	public V getMvpView() {
		return (V) this;
	}


	@Override
	protected void onDestroy() {
		super.onDestroy();
		mActivityDelegate.onDestroy();

	}

	/**
	* 初始化，获取控件
	*/
	protected abstract void init();

	/*
	*用于获取布局id
	**/
	protected abstract int getLayoutResId();


}
